
package com.sise.dubbo.config.filterSpi;

import com.alibaba.dubbo.rpc.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @author linhao
 * @date 2019/5/5
 * @Version V1.0
 */
public class IpFilter implements Filter {

    private static final Logger LOGGER = LoggerFactory.getLogger(IpFilter.class);

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        //consumer名称
        String applicationName = invocation.getAttachments().get("application");
        Map<String, String> params = invoker.getUrl().getParameters();

        //接口的名称
        String service = invoker.getInterface().getName();
        //客户端ip
        String clientIp = RpcContext.getContext().getRemoteHost();
        LOGGER.error("service={},clientip={},application={}", service, clientIp, applicationName);
        System.out.println("权限校验");
        //继续执行rpc处理
        return invoker.invoke(invocation);
    }
}
